package cn.globalph.housekeeper.data.model

import cn.globalph.housekeeper.R
import cn.globalph.housekeeper.data.TokenStorage


data class Task(
    var id: String,
    var actual_end_date: String?,
    var actual_start_date: String?,
    var address: String,
    var area: String,
    var attentions: String,
    var confirmed: Boolean,
    var description: String,
    var district: String,
    var exp_end_date: String?,
    var exp_start_date: String?,
    var hasCleaner: String,
    var hasTowelBox: String,
    var housekeeper: String,
    var location: String,
    var name: String,
    var order_category: String,
    var order_duration: String,
    var order_type: String,
    var phone: String,
    var remark: String,
    var remindMsg: String,
    var service_basic_id: String,
    var service_category: String,
    var service_seq: String,
    var status: String,
    var tot: String,
    var hasCheck:Boolean = false
) {
    val expDuration: String
        get() {
            if(exp_start_date.isNullOrEmpty() && exp_end_date.isNullOrEmpty()){
                return "预期时间："
            }
            if(exp_start_date.isNullOrEmpty()){
                val temp = exp_end_date!!.split(" ")
                if(temp.size!=2 || temp[1].length<5){
                    return "预期时间："
                }
                return "预期时间：-${temp[1].substring(0,5)}"
            }

            if(exp_end_date.isNullOrEmpty()){
                val temp = exp_start_date!!.split(" ")
                if(temp.size!=2 || temp[1].length<5){
                    return "预期时间："
                }
                return "预期时间：${temp[1].substring(0,5)}-"
            }
            val tempStart = exp_start_date!!.split(" ")
            val tempEnd = exp_end_date!!.split(" ")
            if (tempStart.size != 2 || tempEnd.size != 2
                ||tempStart[1].length<5 || tempEnd[1].length<5)
                return "预期时间："
            return "预期时间：${tempStart[1].substring(0,5)}-${tempEnd[1].substring(0,5)}(${order_duration}小时)"
        }

    var actualDuration: String
        get() {
            if (actual_start_date == null) return "实际时间："
            if (actual_end_date == null){
                val tempStart = actual_start_date!!.split(" ")
                if(tempStart.size != 2 || tempStart[1].length<5){
                    return "实际时间："
                }
                return "实际时间：${tempStart[1].substring(0,5)}-"
            }
            val tempStart = actual_start_date!!.split(" ")
            val tempEnd = actual_end_date!!.split(" ")
            if (tempStart.size != 2 || tempEnd.size != 2
                ||tempStart[1].length<5 || tempEnd[1].length<5)
                return "实际时间："
            return "实际时间：${tempStart[1].substring(0,5)}-${tempEnd[1].substring(0,5)}"
        }
    set(value) {

    }

    val serverType: String
        get() {
            return "$area\t$service_category"
        }

    val customInfo:String
    get() {
        return if(TokenStorage.profile?.rolecode == "HOUSE_SUPERVISOR"){
            "$name\t$phone"
        }else{
            name
        }
    }

    val totalAddress:String
    get() {
        return "$district $address"
    }

    val lng:Double
    get() {
        val temps = location.split(",")
        return if(temps.size != 2){
            -1.0
        }else{
            temps[1].toDouble()
        }
    }

    val lat:Double
    get() {
        val temps = location.split(",")
        return if(temps.size != 2){
            -1.0
        }else{
            temps[0].toDouble()
        }
    }

    val remarkShow:Boolean
    get() {
        return remark != ""
    }

    val attentionShow:Boolean
        get() {
            return attentions != ""
        }

    val lineShow:Boolean
    get() {
        return remarkShow||attentionShow
    }

    val statusPic:Int
    get() {
        return when (status) {
            "SERVICED" -> R.drawable.ic_task_completed
            else -> R.drawable.ic_task_conformed
        }
    }

    val statusPicShow:Boolean
    get() {
        return status == "SERVICED" || confirmed
    }
}